#ifndef _ascendancy_game_core_
#define _ascendancy_game_core_

#include <iostream>
#include <vector>
#include <math.h>
#include <QtXml>

#include "solar_system.h"
#include "game_params.h"
#include "planet.h"

#define GAME_CORE_GALAXY_MAX_SIZE	200

#define GAME_CORE_WHITE_LINK		0
#define GAME_CORE_RED_LINK		1
#define GAME_CORE_GREEN_LINK		2

#define GAME_CORE_DISTANCE_RED_LINK	120

#define GAME_CORE_MAX_PLANETS_IN_SYSTEM	8

struct		vortexCoords
{
  int		sysId1;
  int		sysId2;
  int		linkType;
  int		size;
};

class		GameCore
{

  
public:

  GameCore();
  ~GameCore();
  
  // init functions
 
  void		generate(GameParams *gameParams);
  std::vector<SolarSystem*> *getSolarSystems();

  std::vector<SolarSystem*> systems;
  std::vector<vortexCoords*> vortexList;
  std::vector<Planet*> planetList;

private:
  
  // init data
  GameParams	*gameParams;
  // possible star names
  std::vector<std::string> namesList;

  void		cleanData();
  // solar system functions
  void		createSystems();
  bool		coordsAlreadyExist(int x, int y, int z);
  void		createNameList();
  // vortex generation functions
  void		createVortex();
  int		nbOfLinksInSystem(int sys);
  void		createVortexRings(int sys);
  void		chooseClosestSystem(int sys);
  int		getDist(int sys1, int sys2);
  void		linkToClosest(int sys11, int sys12, int sys21, int sys22);
  void		forceLink(int sys);
  void		addLink(int sys1, int sys2);
  // planet creation functions
  void		createPlanets();
  bool		checkPlanetCoordsNotUsed(int sysId, int x, int y, int z);
};


#endif
